﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace Common
{
    public class Settings
    {
        private static Settings _instance;
        public static Settings Instance
        {
            get
            {
                lock (InstanceLock)
                {
                    if (_instance == null) _instance = Serializer.TryDesSerialize<Settings>(ImagePath);
                    if (_instance == null) _instance = new Settings();
                }
                return _instance;
            }
        }

        private Settings(SerializationInfo info, StreamingContext context)
        {
            this.StorageDirectory = info.TryGetValue<string>("StorageDirectory");
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("StorageDirectory", StorageDirectory);
        }

        private Settings()
        {

        }

        private string _storageDirectory = AppDomain.CurrentDomain.BaseDirectory;
        public string StorageDirectory
        {
            get { return _storageDirectory.Substring(0, _storageDirectory.Length - 1); }
            set { _storageDirectory = value; }
        }

        private static readonly object InstanceLock = new object();
        private static readonly string ImagePath = AppDomain.CurrentDomain.BaseDirectory + "config.bs";
    }
}
